<template>
    <ul>
        <li 
        v-for="(item, index) in head" 
        @click="selectedIndex = index"
        :class="{ active: index === selectedIndex }"
        >
            {{ item.title }}
        </li>
    </ul>
    <div class="box">
        <div 
        v-for="(item, index) in body"
        :class="{ selected: index === selectedIndex }"
        >
            {{ item.content }}
        </div>
    </div>
    
</template>

<script setup>
import axios from 'axios';
import { onMounted, ref } from 'vue'
const selectedIndex = ref(0)
const head = ref([])
const body = ref([])
const getData = async() => {
    let { data } = await axios({
        method: 'get',
        url: 'http://127.0.0.1:5000/tab'
    })
    head.value = data.title
    body.value = data.content
}
onMounted(() => {
    getData()
})

</script>

<style scoped>
* {
padding: 0;
margin: 0;
}
ul {
display: flex;
}
li {
list-style-type: none;
height: 30px;
width: 40px;
border: 1px solid black;
display: flex;
justify-content: center;
align-items: center;
}
li:hover {
cursor: pointer;
}
.box {
height: 60px;
width: 123px;
border: 1px solid black;
display: flex;
justify-content: center;
align-items: center;
}
.active {
background-color: aqua;
}
.box > div {
display: none;
}
.box .selected {
display: block;
}
</style>